import React, { Component } from "react";
import { Route, Routes, Redirect, Navigate } from "react-router-dom";
import Home from "./components/Home";
import About from "./components/About";
import MyNavLink from "./components/MyNavLink";
export default class App extends Component {
  render() {
    return (
      <div>
        <div className="row">
          <div className="col-xs-offset-2 col-xs-8">
            <div className="page-header">
              <h2>React Router Demo</h2>
            </div>
          </div>
        </div>
        <div className="row">
          <div className="col-xs-2 col-xs-offset-2">
            <div className="list-group">
              {/* 封装自己的NavLink */}
              <MyNavLink to="/home">Home</MyNavLink>
              <MyNavLink to="/about">About</MyNavLink>

              {/* <NavLink className="list-group-item" to="/home">
                Home
              </NavLink>
              <NavLink className="list-group-item" to="/about">
                About
              </NavLink> */}
            </div>
          </div>
          <div className="col-xs-6">
            <div className="panel">
              <div className="panel-body">
                {/* 注册路由 */}
                <Routes>
                  {/* 精准匹配 */}
                  <Route path="/home" element={<Home />} />

                  {/* 开启模糊匹配 */}
                  <Route path="/about/*" element={<About />} />

                  {/* v5重定向 v6不再适用 */}
                  {/* <Redirect to="/home" /> */}

                  {/* v6 Navigate重定向 */}
                  <Route path="*" element={<Navigate to="/home" />} />
                </Routes>
              </div>
            </div>
          </div>
        </div>
      </div>
    );
  }
}
